//
//  HSYBaseQRCodeViewController+UI.m
//  高仿暴走斗图
//
//  Created by key on 16/3/23.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYBaseQRCodeViewController+UI.h"

static NSInteger kActivityIndicatorViewTag = 1997;

@implementation HSYBaseQRCodeViewController (UI)


- (void)addObserver {
    [self addObserver:self forKeyPath:kQRCodeString];
}

- (void)removeKVO {
    [self removeKVO:self forKeyPath:kQRCodeString];
}

- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath {
    
    [self addObserver:observer forKeyPath:keyPath options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}

- (void)removeKVO:(NSObject *)observer forKeyPath:(NSString *)keyPath {
    
    [self removeObserver:observer forKeyPath:keyPath];
}

- (void)addNavigationItemWithIsRight:(BOOL)isRight itemTypes:(NSArray *)itemTypes {
    
}


- (void)showActivityIndicatorViewInParentView:(UIView *)parentView {
    
    if (!parentView) {
        return;
    }
    
    for (id obj in parentView.subviews) {
        if ([obj isKindOfClass:[UIActivityIndicatorView class]]) {
            [obj removeFromSuperview];
        }
    }
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:parentView.bounds];
    activityIndicator.tag = kActivityIndicatorViewTag -101;
    [parentView addSubview:activityIndicator];
    activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    [activityIndicator startAnimating];
    
}

- (void)stopACtivityIndicatorViewInParentView:(UIView *)parentView {
    
    if (!parentView) {
        return;
    }
    UIActivityIndicatorView *activityIndicator = (UIActivityIndicatorView *)[parentView viewWithTag:kActivityIndicatorViewTag -101];
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
    activityIndicator = nil;
}


@end
